package com.java110.mall.goods.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.mainCategory.MainCategoryProductDto;
import com.java110.intf.goods.IMainCategoryProductInnerServiceSMO;
import com.java110.mall.goods.dao.IMainCategoryProductServiceDao;
import com.java110.po.mainCategory.MainCategoryProductPo;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 主目录商品内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class MainCategoryProductInnerServiceSMOImpl extends BaseServiceSMO implements IMainCategoryProductInnerServiceSMO {

    @Autowired
    private IMainCategoryProductServiceDao mainCategoryProductServiceDaoImpl;


    @Override
    public int saveMainCategoryProduct(@RequestBody MainCategoryProductPo mainCategoryProductPo) {
        int saveFlag = 1;
        mainCategoryProductServiceDaoImpl.saveMainCategoryProductInfo(BeanConvertUtil.beanCovertMap(mainCategoryProductPo));
        return saveFlag;
    }

    @Override
    public int updateMainCategoryProduct(@RequestBody MainCategoryProductPo mainCategoryProductPo) {
        int saveFlag = 1;
        mainCategoryProductServiceDaoImpl.updateMainCategoryProductInfo(BeanConvertUtil.beanCovertMap(mainCategoryProductPo));
        return saveFlag;
    }

    @Override
    public int deleteMainCategoryProduct(@RequestBody MainCategoryProductPo mainCategoryProductPo) {
        int saveFlag = 1;
        mainCategoryProductPo.setStatusCd("1");
        mainCategoryProductServiceDaoImpl.updateMainCategoryProductInfo(BeanConvertUtil.beanCovertMap(mainCategoryProductPo));
        return saveFlag;
    }

    @Override
    public List<MainCategoryProductDto> queryMainCategoryProducts(@RequestBody MainCategoryProductDto mainCategoryProductDto) {

        //校验是否传了 分页信息

        int page = mainCategoryProductDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            mainCategoryProductDto.setPage((page - 1) * mainCategoryProductDto.getRow());
        }

        List<MainCategoryProductDto> mainCategoryProducts = BeanConvertUtil.covertBeanList(
                mainCategoryProductServiceDaoImpl.getMainCategoryProductInfo(BeanConvertUtil.beanCovertMap(mainCategoryProductDto)),
                MainCategoryProductDto.class);

        return mainCategoryProducts;
    }


    @Override
    public int queryMainCategoryProductsCount(@RequestBody MainCategoryProductDto mainCategoryProductDto) {
        return mainCategoryProductServiceDaoImpl.queryMainCategoryProductsCount(BeanConvertUtil.beanCovertMap(mainCategoryProductDto));
    }

    @Override
    public List<MainCategoryProductDto> queryMainCategoryAllGoods(@RequestBody MainCategoryProductDto mainCategoryProductDto) {
        int page = mainCategoryProductDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            mainCategoryProductDto.setPage((page - 1) * mainCategoryProductDto.getRow());
        }

        List<MainCategoryProductDto> mainCategoryProducts = BeanConvertUtil.covertBeanList(
                mainCategoryProductServiceDaoImpl.queryMainCategoryAllGoods(BeanConvertUtil.beanCovertMap(mainCategoryProductDto)), MainCategoryProductDto.class);

        return mainCategoryProducts;
    }

    @Override
    public List<MainCategoryProductDto> queryMainCategoryAllServs(@RequestBody MainCategoryProductDto mainCategoryProductDto) {
        int page = mainCategoryProductDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            mainCategoryProductDto.setPage((page - 1) * mainCategoryProductDto.getRow());
        }

        List<MainCategoryProductDto> mainCategoryProducts = BeanConvertUtil.covertBeanList(
                mainCategoryProductServiceDaoImpl.queryMainCategoryAllServs(BeanConvertUtil.beanCovertMap(mainCategoryProductDto)), MainCategoryProductDto.class);

        return mainCategoryProducts;
    }


    public IMainCategoryProductServiceDao getMainCategoryProductServiceDaoImpl() {
        return mainCategoryProductServiceDaoImpl;
    }

    public void setMainCategoryProductServiceDaoImpl(IMainCategoryProductServiceDao mainCategoryProductServiceDaoImpl) {
        this.mainCategoryProductServiceDaoImpl = mainCategoryProductServiceDaoImpl;
    }
}
